<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class home extends CI_Controller {
	function __construct() {
		parent::__construct();
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("If-Modified-Since: Mon, 22 Jan 2008 00:00:00 GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Cache-Control: private");
		header("Pragma: no-cache");
		$this->load->model('mhome');
		$this->load->model('forum_model');
		$this->load->helper('forum');
		$this->allsession = $this->session->all_userdata();
		$this->sesi = $this->allsession;
	}

	function index(){
		$data['menu_dinamis'] = $this->getdisplay('menu_index');
		$data['menu_samping'] = $this->getdisplay('menu_samping');	
		$data['headline'] = $this->getdisplay('headline');	
		$data['berita'] = $this->getdisplay('berita');		
		$data['content'] = 'beranda';
		$data['type'] = 'beranda';
		$this->load->view('index', $data);
	}
	
	function content($type="", $param1="", $param2=""){
		$data['menu_dinamis'] = $this->getdisplay('menu_index');
		$data['menu_samping'] = $this->getdisplay('menu_samping');
		$data['headline'] = $this->getdisplay('headline');		
		$data['berita'] = $this->getdisplay('berita');		
		$data['type']=$type;
		switch($type){
			case 'beranda':
				$data['content'] = 'beranda';
			break;
			case 'get':
				$exp_param1 = explode('-', $param1);
				$data['content'] = 'profil_dinas';
				$data['param_chart'] = $exp_param1[1];
				$data['menu_id'] = $exp_param1[0];
				if($exp_param1[1] == 'Y'){
					$query = $this->db->get_where('cl_charttable', array('cl_subkategori_content_id'=>$exp_param1[0]))->row();
					if($query){
						$data['chart'] = $query;
					}else{
						$data['chart'] = "";
					}
				}
				
				$datarecord = $this->mhome->getdata('kontent', $exp_param1[0]);
				$data['row'] = $datarecord; //perubahan menampilkan gambar
				if($datarecord){
					$data['recordisi'] = $datarecord->isi;
				}else{
					$data['recordisi'] = "SORRY NO CONTENT";
				}
			break;
			case "headline":
				$data['content'] = 'headline';
				$data['isi']=$this->db->get_where('tbl_headline',array('id'=>$param1))->row();
			break;
			
			case "berita":
				$data['content'] = 'berita';
				$data['isi']=$this->db->get_where('tbl_berita',array('id'=>$param1))->row();
			break;
			
			case "statis":
				$data['content'] = 'statis';
				$data['cat'] = $param1;
				//$data['isi']=$this->db->get_where('tbl_berita',array('id'=>$param1))->row();
				
			break;
			
			case 'forum':
				if ($param1=="" || $param2=="") {
					$forumid	= ""; 
					$permalink	= "";
				} else {
					$forumid	= $param1; 
					$permalink	= $param2;
				}
				
				
				if ($forumid == "") {
					$parent = 0;
				} else {
					$parent = $forumid;
				}
				
				/*$data['sesi'] = $this->sesi;*/
				if ($this->session->userdata('username') != "") {
					$data['logged_in'] = TRUE;
				} else {
					$data['logged_in'] = FALSE;
				}

				$getforum = $this->forum_model->getdata('tbl_forum_map',array('parent'=>$parent,'status'=>1), array('forumid','DESC'));
				
				if(sizeOf($getforum) > 0) {
					$data['content'] = 'forum';
					
					$result_array = array();
					$sub_array	  = array();
				
					foreach ($getforum as $get=>$g) {
					$subforum = $this->forum_model->getdata('v_foruminfo',array('parent'=>$g['forumid'],'status'=>1), array('forumid','DESC'));
					
						$num = 1;
						foreach($subforum as $sub) {
							$mods = $num % 2;
							if ($mods == 0) {
								$sub['flag'] = "genap";
							} else {
								$sub['flag'] = "ganjil";
							}
							array_push($sub_array, $sub);
							$num++;
						}
						$g['subforum'] = $sub_array;
						$sub_array = array();
						array_push($result_array, $g);
					}
					
					$data['forum_mapping'] = $result_array;
					
					/*header('Content-Type: application/json');
					echo json_encode($result_array);
					die();*/
				} else {
					$data['content'] = 'thread';
					$data['thread'] = $this->forum_model->getdata('tbl_forum_map', array('forumid'=>$forumid));
					$data['topic']  = $this->forum_model->getdata('v_threadinfo', array('forumid'=>$forumid, 'status'=>1), array('threadid','DESC'));
				}
			break;
			
			case 'thread':
				$this->load->library('pagination');
				if ($param1=="" || $param2=="") {
					$idthread	= ""; 
					$permalink	= ""; 
				} else {
					$idthread	= $param1; 
					$permalink	= $param2;
				}
				$pos		= "";
				
				$data['content'] = 'viewthread';
				$data['sesi'] = $this->sesi;
				
				if ($this->session->userdata('username') != "") {
					$data['logged_in'] = TRUE;
				} else {
					$data['logged_in'] = FALSE;
				}
				
				if($pos == "") { $pos = 0; }
				$limit = 10;
				$total = $this->forum_model->countdata('v_userthread', array('threadid'=>$idthread));
				
				$config = array();
				$config['base_url'] = base_url().'forum/thread/'.$idthread.'/'.$permalink;
				$config["total_rows"] = $total;
				$config["per_page"] = $limit;
				$config["uri_segment"] = 5;
				
				$config['first_url'] = base_url().'forum/thread/'.$idthread.'/'.$permalink; 
				$config['full_tag_open'] = "";
				$config['full_tag_close'] = "";
				$config['cur_tag_open'] = "<span class=\"current_page\">";
				$config['cur_tag_close'] = "</span>";
				
				$this->pagination->initialize($config);

				$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
				
				$data['thread'] = $this->forum_model->getdata('v_userthread', array('threadid'=>$idthread, 'level'=>0));
				$data['post'] = $this->forum_model->getdata('v_userthread', array('threadid'=>$idthread), array('threadid','ASC'), array($pos, $config["per_page"]));
				
				$data["pagination"]   = $this->pagination->create_links();
			break;
			case 'cari_konten':
				$keynya_sicari_ini = $this->input->post('key', TRUE, TRUE);
				$keynya_sicari_ini = preg_replace('/[^ \w]+/', '', $keynya_sicari_ini);
				$hasilcari_konten = $this->mhome->getdata('cari_konten', $keynya_sicari_ini);
				$hasilcari_berita = $this->mhome->getdata('cari_berita', $keynya_sicari_ini);
				//$hasilcari_forum  = $this->mhome->getdata('cari_forum', $keynya_sicari_ini);
				$data['hasil_konten'] = $hasilcari_konten;
				$data['hasil_berita'] = $hasilcari_berita;
				//$data['hasil_forum'] = $hasilcari_forum;
				$data['keyword'] = $keynya_sicari_ini;
				$data['content'] = 'cari';
			break;
			
		}
		$this->load->view('index', $data);
	}
	
	function getchart($type=''){
		$x=array();
		$y=array();
		$data_y=array();
		$chart=array();
		$table="";
		$no=1;
		$where="WHERE 1=1 ";
		if($this->input->post('menu_id')=='28'){$where .=" AND flag='D' ";} if($this->input->post('menu_id')=='29'){$where .=" AND flag='L' ";}
		$sql="SELECT * FROM $type ".$where." ORDER BY tahun DESC limit 0,5";
		$json = array();
		$kom=$this->db->query($sql)->result_array();
		switch($type){
			case 'tbl_kependudukan':
						$table .='<table width="100%">';
						$table .='<tr><td style="text-align: center;">No</td><td  style="text-align: center;">Tahun</td><td  style="text-align: right;">Jumlah Penduduk</td><td  style="text-align: center;">Jumlah Pencari Kerja</td></tr>';
						$json['bar']=array();
						foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['jumlah_penduduk'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td><td  style="text-align: center;">'.$v['tahun'].'</td><td  style="text-align: right;">'.number_format($v['jumlah_penduduk'],2).'</td><td  style="text-align: right;">'.number_format($v['jumlah_pencari_kerja'],2).'</td></tr>';
							$no++;
							
						}
					$y[]=array('name'=>'Data','data'=>$data_y);
					$table .='</table>';
	
			break;
			case 'tbl_pertumbuhan_ekonomi':
						$table .='<table width="100%">';
						$table .='<tr><td style="text-align: center;">No</td><td  style="text-align: center;">Tahun</td><td  style="text-align: right;">Inflasi</td><td  style="text-align: center;">Satuan</td></tr>';
						$json['bar']=array();
						
						foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['inflasi'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td><td  style="text-align: center;">'.$v['tahun'].'</td><td  style="text-align: right;">'.number_format($v['inflasi'],1).'</td><td  style="text-align: center;">%</td></tr>';
							$no++;
						}
						$y[]=array('name'=>'Data','data'=>$data_y);
						$table .='</table>';
			break;
			
			case 'tbl_komoditi_value':
						$table .='<table width="100%">';
						$table .='<tr><td style="text-align: center;">No</td><td  style="text-align: center;">Tahun</td><td  style="text-align: right;">Jumlah</td><td  style="text-align: center;">Satuan</td></tr>';
						$json['bar']=array();
						$sql =" SELECT A.* FROM tbl_komoditi_value A
								LEFT JOIN cl_komoditi B ON A.cl_komoditi_id=B.id
								LEFT JOIN cl_sektor_potensi C ON B.cl_sektor_potensi_id=C.id 
								WHERE C.cl_subkategori_content_id=".$this->input->post('menu_id')." order by A.tahun DESC limit 0,5";
						$kom=$this->db->query($sql)->result_array();
						
						foreach($kom as $v){
							$table .='<tr><td  style="text-align: center;">'.$no.'</td><td  style="text-align: center;">'.$v['tahun'].'</td><td  style="text-align: right;">'.number_format($v['jumlah'],2).'</td><td  style="text-align: center;">'.$v['satuan'].'</td></tr>';
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['jumlah'];
							$no++;
							
						}
						$table .='</table>';
						$y[]=array('name'=>'Data','data'=>$data_y);
			break;
			case 'tbl_pdrb':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td><td  style="text-align: center;">Tahun</td><td  style="text-align: center;">PMDN</td><td  style="text-align: center;">PMA</td><td  style="text-align: center;">PDRB</td>';
				$data_y2=array();
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['pma'];
							$data_y2[]=(float)$v['pdrb'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td><td  style="text-align: center;">'.$v['tahun'].'</td><td  style="text-align: right;">'.number_format($v['pmdn'],1).' ('.$v['satuan_pmdn'].')</td><td  style="text-align: right;">'.number_format($v['pma'],1).' ('.$v['satuan_pma'].')</td><td  style="text-align: right;">'.number_format($v['pdrb'],1).' ('.$v['satuan_pdrb'].')</td></tr>';
							$no++;
				}
				$y[]=array('name'=>'PMA','data'=>$data_y);
				$y[]=array('name'=>'PDRB','data'=>$data_y2);
				$table .='</table>';
			break;
			
			case 'tbl_kondisi_jalan':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Panjang Jalan</td>
					<td  style="text-align: center;">Kondisi Baik</td>
					<td  style="text-align: center;">Kondisi Sedang</td>
					<td  style="text-align: center;">Kondisi Rusak Ringan</td>
					<td  style="text-align: center;">Kondisi Rusak Berat</td>
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				$data_y5=array();
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['panjang_jalan'];
							$data_y2[]=(float)$v['baik'];
							$data_y3[]=(float)$v['sedang'];
							$data_y4[]=(float)$v['ringan'];
							$data_y5[]=(float)$v['berat'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['panjang_jalan'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['baik'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['sedang'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['ringan'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['berat'],1).' (km)</td>
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Panjang Jalan','data'=>$data_y);
				$y[]=array('name'=>'Kondisi Baik','data'=>$data_y2);
				$y[]=array('name'=>'Kondisi Sedang','data'=>$data_y3);
				$y[]=array('name'=>'Kondisi Rusak Ringan','data'=>$data_y4);
				$y[]=array('name'=>'Kondisi Rusak Berat','data'=>$data_y5);
				$table .='</table>';
			break;
			case 'tbl_panjang_jalan':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Arteri</td>
					<td  style="text-align: center;">Kolektor</td>
					<td  style="text-align: center;">Lokal</td>
					<td  style="text-align: center;">Inspeksi Kanal</td>
					
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['arteri'];
							$data_y2[]=(float)$v['kolektor'];
							$data_y3[]=(float)$v['lokal'];
							$data_y4[]=(float)$v['inspeksi_kanal'];
							
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['arteri'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['kolektor'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['lokal'],1).' (km)</td>
								<td  style="text-align: right;">'.number_format($v['inspeksi_kanal'],1).' (km)</td>
								
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Arteri','data'=>$data_y);
				$y[]=array('name'=>'Kolektor','data'=>$data_y2);
				$y[]=array('name'=>'Lokal','data'=>$data_y3);
				$y[]=array('name'=>'Inspeksi Kanal','data'=>$data_y4);
				
				$table .='</table>';
			break;
			case 'tbl_kendaraan_uji_dephub':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Kendaraan Penumpang</td>
					<td  style="text-align: center;">Bus</td>
					<td  style="text-align: center;">Truk</td>
					<td  style="text-align: center;">Pickup</td>
					<td  style="text-align: center;">Kendaraan Khusus</td>
					<td  style="text-align: center;">Kendaraan Tempelan</td>
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				$data_y5=array();
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['penumpang'];
							$data_y2[]=(float)$v['bus'];
							$data_y3[]=(float)$v['truk'];
							$data_y4[]=(float)$v['pick_up'];
							$data_y5[]=(float)$v['khusus'];
							$data_y6[]=(float)$v['tempelan'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['penumpang'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['bus'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['truk'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['pick_up'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['khusus'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['tempelan'],1).'</td>
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Kendaraan Penumpang','data'=>$data_y);
				$y[]=array('name'=>'Bus','data'=>$data_y2);
				$y[]=array('name'=>'Truk','data'=>$data_y3);
				$y[]=array('name'=>'Pickup','data'=>$data_y4);
				$y[]=array('name'=>'Kendaraan Khusus','data'=>$data_y5);
				$y[]=array('name'=>'Kendaraan Tempelan','data'=>$data_y6);
				$table .='</table>';
			break;
			case 'tbl_kunjungan_kapal':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Samudra</td>
					<td  style="text-align: center;">Nusantara</td>
					<td  style="text-align: center;">Khusus</td>
					<td  style="text-align: center;">Lokal</td>
					
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['samudra'];
							$data_y2[]=(float)$v['nusantara'];
							$data_y3[]=(float)$v['khusus'];
							$data_y4[]=(float)$v['lokal'];
							
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['samudra'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['nusantara'],1).'</td>
								<td  style="text-align: right;">'.number_format($v['khusus'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['lokal'],1).'</td>
								
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Samudra','data'=>$data_y);
				$y[]=array('name'=>'Nusantara','data'=>$data_y2);
				$y[]=array('name'=>'Khusus','data'=>$data_y3);
				$y[]=array('name'=>'Lokal','data'=>$data_y4);
				
				$table .='</table>';
			break;
			
			case 'tbl_kunjungan_kapal_tambatan':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Dermaga Umum</td>
					<td  style="text-align: center;">Dermaga Khusus</td>
				
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['dermaga_umum'];
							$data_y2[]=(float)$v['dermaga_khusus'];
							
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['dermaga_umum'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['dermaga_khusus'],1).'</td>
								
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Dermaga Umum','data'=>$data_y);
				$y[]=array('name'=>'Dermaga Khusus','data'=>$data_y2);
				
				
				$table .='</table>';
			break;
			
			case 'tbl_arus_petikemas':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">'.($this->input->post('menu_id')==28 ? 'Bongkar' : 'Export').'</td>
					<td  style="text-align: center;">'.($this->input->post('menu_id')==28 ? 'Muat' : 'Import').'</td>
				
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=($this->input->post('menu_id')==28 ? (float)$v['bongkar'] : (float)$v['export']);
							$data_y2[]=($this->input->post('menu_id')==28 ? (float)$v['muat'] : (float)$v['import']);
							
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.($this->input->post('menu_id')==28 ? number_format($v['bongkar'],1) : number_format($v['export'],1)).' </td>
								<td  style="text-align: right;">'.($this->input->post('menu_id')==28 ? number_format($v['muat'],1) : number_format($v['import'],1)).'</td>
								
								</tr>';
							$no++;
				}
				$y[]=array('name'=>($this->input->post('menu_id')==28 ? 'Bongkar' : 'Export'),'data'=>$data_y);
				$y[]=array('name'=>($this->input->post('menu_id')==28 ? 'Muat' : 'Import'),'data'=>$data_y2);
				
				
				$table .='</table>';
			break;
			
			case 'tbl_sambungan_telp':
				$table .='<table width="100%">';
				$table .='<tr><td style="text-align: center;">No</td>
					<td  style="text-align: center;">Tahun</td>
					<td  style="text-align: center;">Pelanggan</td>
					<td  style="text-align: center;">Line Services</td>
					<td  style="text-align: center;">Connected Line</td>
					</tr>';
				$data_y2=array();
				$data_y3=array();
				$data_y4=array();
				
				foreach($kom as $v){
							$x[]=$v['tahun'];
							$data_y[]=(float)$v['pelanggan'];
							$data_y2[]=(float)$v['line_service'];
							$data_y3[]=(float)$v['connected_line'];
							$table .='<tr><td  style="text-align: center;">'.$no.'</td>
								<td  style="text-align: center;">'.$v['tahun'].'</td>
								<td  style="text-align: right;">'.number_format($v['pelanggan'],1).' </td>
								<td  style="text-align: right;">'.number_format($v['line_service'],1).'</td>
								<td  style="text-align: right;">'.number_format($v['connected_line'],1).'</td>
								</tr>';
							$no++;
				}
				$y[]=array('name'=>'Pelanggan','data'=>$data_y);
				$y[]=array('name'=>'Line Services','data'=>$data_y2);
				$y[]=array('name'=>'Connected Line','data'=>$data_y3);
				
				
				$table .='</table>';
			break;
			
		}
			//echo join($data_y,',');
		//exit;
		
		
		$chart['x']=$x;
		$chart['y']=$y;
		$chart['table']=$table;
		echo json_encode($chart); 		
	}
	
	function getdisplay($type=''){
		switch($type){
			case 'menu_index':
				$html = "";
				$datakategori = $this->mhome->getdata('kategori_menu_atas');
				foreach($datakategori as $k=>$v){
					$datasubkategori = $this->mhome->getdata('subkategori_menu', $v['id']);
					if($datasubkategori){
						$html .= "<li><a href='#'>".$v['kategori_profil']."</a>";
						$html .= "<ul>";
						foreach($datasubkategori as $a => $b){
							if($b['flag_chart']) $flag_chart = $b['flag_chart'];
							else $flag_chart = "N";
							$bersihinkarakter = preg_replace('/[^ \w]+/', 'a', $b['sub_kategori']);
							$seo_link = strtolower(str_replace(' ', '-', $bersihinkarakter));
							//$html .= 	"<li><a href='".base_url()."home/content/get/".$b['id']."/".$b['flag_chart']."'>".$b['sub_kategori']."</a></li>";
							$html .= 	"<li><a href='".base_url()."konten/".$b['id']."-".$flag_chart."/".$seo_link.".html'>".$b['sub_kategori']."</a></li>";
						}
						$html .= "</ul>";
					}else{
						$html .= "<li><a href=''>".$v['kategori_profil']."</a>";
					}
					$html .= "</li>";
				}
				return $html;
				exit;
			break;
			case 'menu_samping':
				$html = "";			
				$datakategori = $this->mhome->getdata('kategori_menu_samping');
				foreach($datakategori as $k=>$v){
					$datasubkategori = $this->mhome->getdata('subkategori_menu', $v['id']);
					if($datasubkategori){
						$html .= "<p class='menu_head'>".$v['kategori_profil']."</p>";
						$html .= "<div class='menu_body'>";
						foreach($datasubkategori as $a => $b){
							if($b['flag_chart']) $flag_chart = $b['flag_chart'];
							else $flag_chart = "N";
							$bersihinkarakter = preg_replace('/[^ \w]+/', 'a', $b['sub_kategori']);
							$seo_link = strtolower(str_replace(' ', '-', $bersihinkarakter));						
							//$html .= 	"<a href='".base_url()."home/content/get/".$b['id']."/".$b['flag_chart']."'>".$b['sub_kategori']."</a>";
							$html .= 	"<a href='".base_url()."konten/".$b['id']."-".$flag_chart."/".$seo_link.".html'>".$b['sub_kategori']."</a>";
						}
						$html .= "</div>";
					}else{
						$html .= "<p class='menu_head'><a href='#'>".$v['kategori_profil']."</a></p>";
					}
				}
				return $html;
				exit;
			break;
			
			case "headline":
				return $this->db->get('tbl_headline')->result_array();
			break;
			case "berita":
				return $this->db->query('SELECT * FROM tbl_berita ORDER BY tanggal DESC limit 0,10')->result_array();
			break;
			
		}
	}
	
	function tes(){
		$data['judul']='TESSS';
		$data['content'] = 'tes';
		$data['type'] = 'beranda';
		$data['menu_dinamis'] = $this->getdisplay('menu_index');
		$data['menu_samping'] = $this->getdisplay('menu_samping');
		$this->load->view('index', $data);
	}
	
	function tes_data(){
		$x=array();
		$y=array();
		$data_y=array();
		$chart=array();
		$sql="select * from tbl_kependudukan ";
		
		$json['bar']=array();
		$kom=$this->db->query($sql)->result_array();
		foreach($kom as $v){
			//$val=$v['jumlah_penduduk'];
			//$json['bar'][$v['tahun']]=(int)$val;	
			$x[]=$v['tahun'];
			$data_y[]=(float)$v['jumlah_penduduk'];
			
			
		}
		
		//echo join($data_y,',');
		//exit;
		$y[]=array('name'=>'Data','data'=>$data_y);
		$chart['x']=$x;
		$chart['y']=$y;
		echo json_encode($chart);
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */